package org.nnxy.foodboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.nnxy.foodboot.entity.Recipe;
import org.nnxy.foodboot.entity.RecommendationRecord;
import org.nnxy.foodboot.mapper.RecommendationRecordMapper;
import org.nnxy.foodboot.service.RecommendationRecordService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 推荐记录服务实现类
 */
@Service
@RequiredArgsConstructor
public class RecommendationRecordServiceImpl extends ServiceImpl<RecommendationRecordMapper, RecommendationRecord> implements RecommendationRecordService {

    private final RecommendationRecordMapper recommendationRecordMapper;


    @Override
    public Page<Recipe> selectPage(Integer current, Integer size, String userId) {
        int offset = (current - 1) * size;
        List<Recipe> result = baseMapper.selectRRPage(current,size, userId, offset);
        Page<Recipe> page = new Page<Recipe>();
        page.setRecords(result);
        page.setSize(size);
        page.setCurrent(current);
        page.setTotal(getSize(userId));
        return page;
    }
    public Long getSize(String userId) {
        LambdaQueryWrapper<RecommendationRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RecommendationRecord::getUserId, userId);
        return recommendationRecordMapper.selectCount(queryWrapper);

    }
}